﻿/*
 * Programer: JR Padfield
 * Description: Handles data from files client side.
 * Version: 1
 * Date: 12/17/13 * 
 */

using System.Collections.Generic;
using System.IO;
using TheWorldLibrary.Items;
using TheWorldLibrary.Skills;
using TheWorldLibrary.Characters;
using TheWorldLibrary;

namespace TheWorld.Components
{
    static class DataManager
    {
        #region Field Region

        static Dictionary<string, ArmorData> armor = new Dictionary<string, ArmorData>();
        static Dictionary<string, WeaponData> weapons = new Dictionary<string, WeaponData>();
        static Dictionary<string, ShieldData> shields = new Dictionary<string, ShieldData>();

        static Dictionary<string, KeyData> keys = new Dictionary<string, KeyData>();
        static Dictionary<string, ChestData> chests = new Dictionary<string, ChestData>();

        static Dictionary<string, EntityData> entities = new Dictionary<string, EntityData>();

        static Dictionary<string, SkillData> skills = new Dictionary<string, SkillData>();

        #endregion

        #region Property Region

        public static Dictionary<string, ArmorData> ArmorData
        {
            get { return armor; }
        }

        public static Dictionary<string, WeaponData> WeaponData
        {
            get { return weapons; }
        }

        public static Dictionary<string, ShieldData> ShieldData
        {
            get { return shields; }
        }

        public static Dictionary<string, EntityData> EntityData
        {
            get { return entities; }
        }

        public static Dictionary<string, ChestData> ChestData
        {
            get { return chests; }
        }

        public static Dictionary<string, KeyData> KeyData
        {
            get { return keys; }
        }

        public static Dictionary<string, SkillData> SkillData
        {
            get { return skills; }
        }

        #endregion

        #region Constructor Region
        #endregion

        #region Method Region

        public static void ReadEntityData()
        {
            string[] filenames = Directory.GetFiles(@"Content\Game\Classes", "*.xml");

            foreach (string name in filenames)
            {
                string filename = @"Content\Game\Classes\" + Path.GetFileName(name);
                EntityData data = XNASerializer.Deserialize<EntityData>(filename);
                EntityData.Add(data.EntityName, data);
            }
        }

        public static void ReadArmorData()
        {
            string[] filenames = Directory.GetFiles(@"Content\Game\Items\Armor", "*.xml");

            foreach (string name in filenames)
            {
                string filename = @"Content\Game\Items\Armor\" + Path.GetFileName(name);
                ArmorData data = XNASerializer.Deserialize<ArmorData>(filename);
                ArmorData.Add(data.Name, data);
            }
        }

        public static void ReadWeaponData()
        {
            string[] filenames = Directory.GetFiles(@"Content\Game\Items\Weapon", "*.xml");

            foreach (string name in filenames)
            {
                string filename = @"Data\Items\Weapon\" + Path.GetFileName(name);
                WeaponData data = XNASerializer.Deserialize<WeaponData>(filename);
                WeaponData.Add(data.Name, data);
            }
        }

        public static void ReadShieldData()
        {
            string[] filenames = Directory.GetFiles(@"Content\Game\Items\Shield", "*.xml");

            foreach (string name in filenames)
            {
                string filename = @"Content\Game\Items\Shield\" + Path.GetFileName(name);
                ShieldData data = XNASerializer.Deserialize<ShieldData>(filename);
                ShieldData.Add(data.Name, data);
            }
        }

        public static void ReadKeyData()
        {
            string[] filenames = Directory.GetFiles(@"Content\Game\Keys", "*.xml");

            foreach (string name in filenames)
            {
                string filename = @"Content\Game\Keys\" + Path.GetFileName(name);
                KeyData data = XNASerializer.Deserialize<KeyData>(filename);
                KeyData.Add(data.Name, data);
            }
        }

        public static void ReadChestData()
        {
            string[] filenames = Directory.GetFiles(@"Content\Game\Chests", "*.xml");

            foreach (string name in filenames)
            {
                string filename = @"Content\Game\Chests\" + Path.GetFileName(name);
                ChestData data = XNASerializer.Deserialize<ChestData>(filename);
                ChestData.Add(data.Name, data);
            }
        }

        public static void ReadSkillData()
        {
            string[] filenames = Directory.GetFiles(@"Content\Game\Skills", "*.xml");

            foreach (string name in filenames)
            {
                string filename = @"Content\Game\Skills\" + Path.GetFileName(name);
                SkillData data = XNASerializer.Deserialize<SkillData>(filename);
                SkillData.Add(data.Name, data);
            }
        }

        #endregion

        #region Virtual Method region
        #endregion
    }
}
